package per.turtle.system.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import per.turtle.common.core.annotation.ITree;
import per.turtle.common.core.annotation.validate.MaxSizeWithCharset;
import per.turtle.common.core.web.entity.BaseEntity;

import javax.validation.constraints.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author turtle
 */
@Schema(name = "SysDept", description = "部门")
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sys_dept")
public class SysDept extends BaseEntity implements ITree {

    private static final long serialVersionUID = 2L;

    @Schema(description = "部门主键")
    @TableId(type = IdType.ASSIGN_UUID)
    private String deptId;

    @Schema(description = "父部门ID")
    private String parentId;

    @Schema(description = "祖级列表")
    private String ancestors;

    @Schema(description = "部门名称")
    @NotBlank(message = "部门名称不能为空")
    @MaxSizeWithCharset(max = 32, message = "部门名称超过限定长度！")
    private String deptName;

    @Schema(description = "显示顺序")
    @Max(value = 9999, message = "显示顺序取值范围在4位数以内")
    @Min(value = 1, message = "显示顺序取值需大于0")
    @NotNull(message = "显示顺序不能为空")
    @OrderBy(asc = true)
    private Integer orderNum;

    @Schema(description = "负责人")
    private String leader;

    @Schema(description = "联系电话")
    @MaxSizeWithCharset(max = 11, message = "联系电话长度不能超过11个字符")
    private String phone;

    @Schema(description = "邮箱")
    @Email(message = "邮箱格式不正确")
    @MaxSizeWithCharset(max = 50, message = "邮箱超过限定长度！")
    private String email;

    @Schema(description = "部门状态（0：正常；1：停用）")
    private Boolean isDisabled;

    @Schema(description = "父部门名称")
    @TableField(exist = false)
    private String parentName;

    @Schema(description = "子部门")
    @TableField(exist = false)
    private List<SysDept> children = new ArrayList<>();

    @Override
    public List<SysDept> treeChildren() {
        return children;
    }

    @Override
    public String treeId() {
        return deptId;
    }

    @Override
    public String treeName() {
        return deptName;
    }

}
